package com.example.blog.config;/**
 * @作者:不想说话而已
 * @Package:com.example.blog.config
 * @Project:IntelliJ IDEA
 * @Name:TaskPoolConfig
 * @Date:2023/11/25 17:35 周六
 */

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 @作者：不想说话而已
 @Date：2023/11/25 17:35
 */
@EnableAsync
@Configuration
public class TaskPoolConfig {

    @Bean
    public Executor taskPoolLogging(){
        ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
        pool.setCorePoolSize(2); //核心线程数
        pool.setMaxPoolSize(4); //最大线程数
        pool.setQueueCapacity(10); //线程队列
        pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return pool;
    }

    @Bean
    public Executor taskPoolUserInfo(){
        ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
        pool.setCorePoolSize(2); //核心线程数
        pool.setMaxPoolSize(4); //最大线程数
        pool.setQueueCapacity(10); //线程队列
        pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return pool;
    }

    @Bean
    public Executor taskPoolWriting(){
        ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
        pool.setCorePoolSize(2); //核心线程数
        pool.setMaxPoolSize(4); //最大线程数
        pool.setQueueCapacity(10); //线程队列
        pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return pool;
    }

}
